/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace DaveSexton.DocProject.DeploymentSandcastle
{
	[Serializable]
	public struct DeploymentContent : IEquatable<DeploymentContent>
	{
		#region Public Properties
		public static readonly DeploymentContent Empty = new DeploymentContent();

		public Uri Source { get { return source; } }
		public Uri Target { get { return target; } }
		#endregion

		#region Private / Protected
		private readonly Uri source, target;
		#endregion

		#region Constructors
		public DeploymentContent(Uri source, Uri target)
		{
			if (source == null)
				throw new ArgumentNullException("source");

			if (target == null)
				throw new ArgumentNullException("target");

			this.source = source;
			this.target = target;
		}

		public DeploymentContent(string source, string target)
		{
			if (source == null)
				throw new ArgumentNullException("source");

			if (target == null)
				throw new ArgumentNullException("target");

			this.source = new Uri(source);
			this.target = new Uri(target);
		}

		public DeploymentContent(string rootSource, string rootTarget, string fileName)
		{
			if (rootSource == null)
				throw new ArgumentNullException("rootSource");

			if (rootTarget == null)
				throw new ArgumentNullException("rootTarget");

			if (fileName == null)
				throw new ArgumentNullException("fileName");

			this.source = new Uri(Path.Combine(rootSource, fileName));
			this.target = new Uri(Path.Combine(rootTarget, fileName));
		}

		public DeploymentContent(string rootSource, string source, string rootTarget, string target)
		{
			if (rootSource == null)
				throw new ArgumentNullException("rootSource");

			if (source == null)
				throw new ArgumentNullException("source");

			if (rootTarget == null)
				throw new ArgumentNullException("rootTarget");

			if (target == null)
				throw new ArgumentNullException("target");

			this.source = new Uri(Path.Combine(rootSource, source));
			this.target = new Uri(Path.Combine(rootTarget, target));
		}
		#endregion

		#region Methods
		public override int GetHashCode()
		{
			return ((source == null) ? 0 : source.GetHashCode())
				^ ((target == null) ? 0 : target.GetHashCode());
		}

		public override bool Equals(object obj)
		{
			if (obj is DeploymentContent)
				return Equals((DeploymentContent) obj);
			else
				return false;
		}

		public static bool operator ==(DeploymentContent item1, DeploymentContent item2)
		{
			return item1.Equals(item2);
		}

		public static bool operator !=(DeploymentContent item1, DeploymentContent item2)
		{
			return !item1.Equals(item2);
		}
		#endregion

		#region IEquatable<DeploymentContent> Members
		public bool Equals(DeploymentContent other)
		{
			return ((source == null && other.source == null)
				|| (source != null && source.Equals(other.source)))
			&& ((target == null && other.target == null)
				|| (target != null && target.Equals(other.target)));
		}
		#endregion
	}
}
